﻿using Microsoft.Data.SqlClient.Server;
using NewsEntity.Enum;
using NewsEntity.Models;
using NewsSevicer.ResultClass;
using NewsSevicer.ResultClass.InputDto;
using System;
using System.Collections.Generic;
using System.Text;

namespace ExtensionTools
{
    public static class DtoExtensions
    {
        public static OnlineUsers ToEntity(this RegisterUserDto dto)
        {
            return new OnlineUsers
            {
                UserID = dto.UserID,
                Username = dto.Username,
                Password = dto.Password,
                Email = dto.Email,
                LoginTime = dto.LoginTime,
                LogoutTime = dto.LogoutTime,
                Status = dto.Status,
                IPAddress = dto.IPAddress,
                DeviceType = dto.DeviceType,
                BrowserInfo = dto.BrowserInfo,
                SessionID = dto.SessionID,
                Location = dto.Location,
                LastActiveTime = dto.LastActiveTime,
                Role = dto.Role,
            };
        }
        public static userinfo ToDto(this OnlineUsers user)
        {

            return new userinfo { 
            Email = user.Email,
            Status=user.Status==0?UserState.Online:UserState.Invisible,
            UserName = user.Username,
            NickName =user.NickName
            };
        }

        public static UserStorage ToEntity(this UserStorageInputDto dto)
        {
            return new UserStorage
            {
                StorageId = dto.StorageId,
                UserId = dto.UserId,
                TotalSpace = dto.TotalSpace,
                UsedSpace = dto.UsedSpace,
                PlanId = dto.PlanId,
                CreateTime = dto.CreateTime==null?DateTime.Now:dto.CreateTime,
                ExpireTime = dto.ExpireTime

            };
        }

    }

}
